package com.wangsir.dao;

import com.wangsir.entity.Admin;
import com.wangsir.util.JdbcHelper;

import java.rmi.MarshalException;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDao {
    public Admin getByUsername(String username) {
        JdbcHelper jdbcHelper = new JdbcHelper();
        ResultSet resultSet = jdbcHelper.executeQuery("select * from tb_admin where username = ?",username);
        try {
            if(resultSet.next()){
                Admin admin = new Admin();
                admin.setUsername(resultSet.getString("username"));
                admin.setPassword(resultSet.getString("password"));
                return admin;
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            jdbcHelper.closeDB();
        }
        return null;
    }
}
